package com.focus.xyz.union.cases.frontend;

import com.focus.xyz.core.common.annotation.Task;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.union.action.KeyWordAction;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.union.data.InsDataBean;
import com.focus.xyz.union.data.InsDataService;
import com.focus.xyz.union.pages.frontend.FrontMenuList;
import com.focus.xyz.union.pages.frontend.tables.AllProdTable;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;

/**
 * Created by chenmeng on 2016/5/26.
 */
public class ProxyProdTest extends TC {
    private static transient Logger logger = LoggerFactory.getLogger(ProxyProdTest.class);

    private WebDriver driver;
    private KeyWordAction action;

    @BeforeClass
    public void beforeClass() throws Exception{
        action.DelUnionFrontCookie();
    }


    @Parameters({"nodeUrl","browser","userName","password"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser,String userName,String password) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new KeyWordAction(driver);
        action.LoginFront(userName,password);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            super.quit();
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }

    @Task(taskName = "DEL_PRD_SCOPE_PLAT.sql",paras = {"param0=cimon011"})
    @Parameters({"idx"})
    @Test(description = "保险代理人从前台代理产品流程校验")
    public void PROXY_PROD(String idx) throws Exception{
        /*打开菜单*/
        FrontMenuList menuList = new FrontMenuList(driver,action);
        menuList.openMenu(Constants.U_F_PROD_MENU);
        /*在所有产品中搜索产品并代理*/
        InsDataBean bean = InsDataService.getInsDataById(idx);
        AllProdTable ap = new AllProdTable(driver,action);
        ap.inputProd(bean.getProdName());
        ap.clickSearchBtn();
        /*点击搜索之后要等待*/
        action.pause(1000l);
        ap.proxy();
        /*从推荐产品中分别选择性价比、佣金推荐产品代理*/
        ap.linkRecProd();
        ap.proxyProd();
    }
}
